package com.yykj.hospital.server.converter;


import com.yykj.hospital.client.dto.HospitalAdminDTO;
import com.yykj.hospital.server.model.entity.HospitalAdmin;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class HospitalAdminDTOConverter {
    public static HospitalAdminDTO convert(HospitalAdmin hospitalAdmin){
        HospitalAdminDTO dto = new HospitalAdminDTO();
        BeanUtils.copyProperties(hospitalAdmin,dto);
        if(StringUtils.isEmpty(hospitalAdmin.getRoleIds())){
            dto.setRoles(new ArrayList<>());
        }else{
           dto.setRoles(Arrays.asList(hospitalAdmin.getRoleIds().split(",")));
        }
        return dto;
    }

    public static List<HospitalAdminDTO> convert(List<HospitalAdmin> list){
        return list.stream().map(HospitalAdminDTOConverter::convert).collect(Collectors.toList());
    }
}
